package lol.clann.minecraft.springboot.api.bukkit.utils;

import org.bukkit.util.Vector;

import javax.annotation.Nullable;

/**
 *
 * @author pyz
 * @date 2019/6/7 7:45 AM
 */
public interface VectorUtils {
    /**
     * 调整向量长度
     *
     * @param v
     * @param length
     */
    void adjust(Vector v, double length);

    /**
     * 调整向量长度和散射度
     * @param v
     * @param length
     * @param spread
     */
    void adjust(Vector v, double length, double spread);

    <T> T toVec3D(Vector vector);

    <T> T toVec3D(double x, double y, double z);

    <T> Vector fromVec3D(T vec3D);

    /**
     * 获取向量的yaw和pitch
     *
     * @param vector
     * @return
     */
    float[] getDirection(Vector vector);

    /**
     * 设置向量的yaw和pitch
     *
     * @param vector
     * @param yaw       [0,360)
     * @param pitch     [-90,90]
     */
    void setDirection(Vector vector, float yaw, float pitch);

    /**
     * XZ旋转
     *
     * @param vector
     * @param yaw
     */
    void rotateYaw(Vector vector, float yaw);

    /**
     * Y旋转
     *
     * @param vector
     * @param pitch
     */
    void rotatePitch(Vector vector, float pitch);

    /**
     * Returns a new vector with x value equal to the second parameter, along the line between this vector and the
     * passed in vector, or null if not possible.
     *
     * 直线left -> vec的起点坐标为A,终点坐标为B
     * 在AB上找一点(C),使其x坐标为给定的值
     * 若能找到,返回向量A->C
     *
     */
    @Nullable
    Vector getIntermediateWithXValue(Vector left, Vector vec, double x);

    /**
     * Returns a new vector with y value equal to the second parameter, along the line between this vector and the
     * passed in vector, or null if not possible.
     */
    @Nullable
    Vector getIntermediateWithYValue(Vector left, Vector vec, double y);

    /**
     * Returns a new vector with z value equal to the second parameter, along the line between this vector and the
     * passed in vector, or null if not possible.
     */
    @Nullable
    Vector getIntermediateWithZValue(Vector left, Vector vec, double z);

    double squareDistanceTo(Vector left, Vector vec);

    double squareDistanceTo(Vector left, double xIn, double yIn, double zIn);
}
